<?php
namespace Home\Service;

use Think\Service\BasicService;

class ChildrenService extends BasicService {
    public function insert($model) {
        return $this->db->add($model);
    }

    public function AddAll($model) {
        $data = $this->db->addAll($model);
        return $data;
    }

    public function remove($condition) {
        return $this->db->where($condition)->delete();
    }

    public function update($where, $model = array()) {
        return $this->db->where($where)->save($model);
    }

    public function find($condition) {
        return $this->db->where($condition)->find();
    }

    public function query($condition, $limit = array(), $field = '*', $order = '', $join = '') {
        $data = $this->db->join($join)->where($condition)->field($field)->limit($limit['start'], $limit['end'])->order($order)->select();
        return $data;
    }

    public function count($condition) {
        return $this->db->where($condition)->count();
    }

    public function GetWZ($ID) {
        $data = $this->db->field('ts_ck.*,ts_sj.CODE as SJCODE,ts_sg.CODE as SGCODE')->join('ts_sg  on ts_sg.BHCODE = ts_book.WZ_CODE')->join('ts_sj on ts_sg.SJ_ID = ts_sj.BHCODE')->join('ts_ck on ts_ck.BHCODE = ts_sj.CK_ID')->where(array('ts_book.ID' => $ID))->find();
        $data ? $str = $data['P'] . $data['C'] . $data['Z'] . $data['ADDRESS'] . $data['NAME'] . '书架代码:' . $data['SJCODE'] . '书柜代码:' . $data['SGCODE'] : $str = '书籍未入库';
        return $str;
    }

    /*
     * 修改书籍内图
     */
    public function UpdatePic($ID, $save) {
        $this->db->startTrans();
        $OK = $this->db->where(array('BOOK_ID' => $ID))->select();
        $DELOK = 1;
        if ($OK) {
            $DELOK = $this->db->where(array('BOOK_ID' => $ID))->delete();
        }
        if ($DELOK) {
            $ADDOK = $this->db->addAll($save);
            if ($ADDOK) {
                $this->db->commit();
                return 1;
            }
        }
        $this->db->rollback();
        return 0;
    }


}


?>